package cn.ylg.com.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

/**
 * Created by MyPC on 2016/10/20.
 */
public class StudentDbUtils {
    public  static SQLiteDatabase db = null;
    private  static StudentDbUtils dbUtils=null;
    public static StudentDbUtils getInstance(Context context){
        if (dbUtils==null){
            dbUtils = new StudentDbUtils(context);
        }
        return dbUtils;
    }
    private StudentDbUtils(Context context){
        SudentDBOpenHelper helper = new SudentDBOpenHelper(context);
        //获得可写的数据库;
        db = helper.getWritableDatabase();
    }
    /*通过本方法往数据库里写入student（学员）对象*/
    public static long writeStudent(Student student) {


        //通过本contentvalues对象，准备数据字段
        ContentValues values = new ContentValues();
        values.put(StudentContract.StudentEntry.COLUMN_NAME_ENTRY, student.username);
        values.put(StudentContract.StudentEntry.COLUMN_AGE, student.age);
        values.put(StudentContract.StudentEntry.COLUMN_START_CLASS, student.datetime);


/*
        // Which row to update, based on the ID
        String selection = FeedEntry.COLUMN_NAME_ENTRY_ID + " LIKE ?";
        String[] selectionArgs = { String.valueOf(rowId) };*/

        long count =  db.insert(
                StudentContract.StudentEntry.TABLE_NAME,
                null,
                values
        );

        return count;

    }
}
